// pages/mymessagedetail/index.js
const {
  fetch,
  newFetch
} = require('../../utils/fetch')

Page({
  /**
   * 页面的初始数据
   */

  data: {
    messageobj: {},
    specificarea: null,
    detailmessageId: '',
    uploadimgs:[1,3,4,5,]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (wx.getStorageSync('specificarea')) {
      this.setData({
        specificarea: wx.getStorageSync('specificarea')
      })
    }   
    if(options.id) {
      newFetch(`wx/feedback/${this.data.specificarea}/detail/${options.id}`, 'GET').then(res => {
        if (res) {
            this.setData({
              uploadimgs: res.data.imgs.split(','),
              messageobj: res.data
            })
        }
      })
    }
  },

  
  bind_tel(e) {
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset['tel'],
      success() {
      },
      fail() {
      }
    })
  },


  godetail() {
    var that = this;
    // fetch(`wx/message/${this.data.specificarea}/detail`, 'POST', {
    //   id: that.data.detailmessageId
    // }).then(res => {
    //   var details = encodeURIComponent(res.details);
    //   delete res['details']
    //   if (res) {
    //     // 顺风车
    //     if (res.typeone.title == '顺风车' || (res.typetwo && res.typetwo.title == '车找人')) {
    //       wx.navigateTo({
    //         url: '/pages/publishsfcar/index?ediddata=' + JSON.stringify(res) + '&editid=' + that.data.detailmessageId + '&details=' + details
    //       })
    //       return;
    //     }
    //     wx.navigateTo({
    //       url: '/pages/publishlist/index?ediddata=' + JSON.stringify(res) + '&editid=' + that.data.detailmessageId + '&details=' + details
    //     })
    //   }
    // })
    wx.navigateTo({
      url: '/pages/indexDetails/index?id='+ that.data.detailmessageId,
      success: function(res) {
          // 通过eventChannel向被打开页面传送数据
      }
  })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {}
})